<template>
	<view class="">
		<view class="" v-if="identity == 1">
			<userOrder ref="userOrder" :list='order_list'></userOrder>
		</view>
		<view class="" v-if="identity == 2">
			<serverOrder ref="serverOrder" :list='list'></serverOrder>
		</view>

		<u-loading-page :loading="isLoading" loadingText='切换身份中'></u-loading-page>

		<pullUp :status='state'></pullUp>
		<tabbar :value="3"></tabbar>
	</view>
</template>

<script>
	import userOrder from '@/components/sharePage/user/order/order.vue'
	import serverOrder from '@/components/sharePage/server/order/order.vue'
	import {
		pageSize
	} from '@/components/minxins.js' //引入minxins
	import {
		mapGetters,
		mapState
	} from 'vuex';
	export default {
		mixins: [pageSize],
		components: {
			userOrder,
			serverOrder
		},
		data() {
			return {
				order_list: [], //订单列表
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({ //修改导航栏文字
				title: this.identity == 1 ? '我的订单' : '清洗订单'
			})

			if (this.identity == 1) {
				this.getUserAddress()
			} else if (this.identity == 2) {
				this.serviceOrderList()
			}
		},
		onShow() {
			this.getUser()
		},
		methods: {
			getUserAddress() { //用户订单列表
				// console.log(e);
				// if (e) {
				// 	this.page = 1
				// 	this.state = 'loadmore'
				// }
				this.method_name = 'getOrderList'
				this.query = {
					type: this.user_order_active + 1
				}
				this.getList();
			},
			serviceOrderList(e) { //服务端订单列表
				this.method_name = 'serviceOrderList'
				this.query = {
					type: e ? e : 1
				}
				this.getList()
			}
		},
		computed: {
			...mapState({
				identity: state => state.identity,
				user_order_active: state => state.user_order_active,
			})
		},
		watch: {
			identity: {
				handler(news) {
					console.log(news, 88);

					if (news) {

					}
				},
				deep: true,
				immediate: true,
			},
			user_order_active: {
				handler(news) {
					this.page = 1
					this.state = 'loadmore'
					this.getUserAddress()
				},
				deep: true,
			},
			list: {
				handler(news) {
					// console.log(news);
					if (this.identity == 1) {
						let time = new Date().getTime()
						news.map(item => {
							item.countDown = item.endtime_text * 1000 - time
							item.timeData = {}
						})
						this.order_list = news
					}
				},
				deep: true,
				immediate: true,
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
